//
//  LHCameraAuthoritymanager.m
//  LHImagePicker
//
//  Created by 刘辉 lewis on 2018/6/13.
//  Copyright © 2018年 刘辉 lewis. All rights reserved.
//

#import "LHCameraAuthoritymanager.h"

@implementation LHCameraAuthoritymanager
+ (void)lh_requestUserAuthorizationCameraWith:(void(^)(AVAuthorizationStatus status))grantedBlock{
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (authStatus == AVAuthorizationStatusNotDetermined) {
        /** 请求媒体访问权限,如对此方法不确定，请查阅苹果文档 */
        [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
            if (granted) {
                if (grantedBlock) {
                    grantedBlock(AVAuthorizationStatusAuthorized);
                }
            }
        }];
    } else if(authStatus == AVAuthorizationStatusAuthorized) {
        if (grantedBlock) {
            grantedBlock(AVAuthorizationStatusAuthorized);
        }
    } else if(authStatus == AVAuthorizationStatusDenied){
        if (grantedBlock) {
            grantedBlock(AVAuthorizationStatusDenied);
        }
    } else if (authStatus == AVAuthorizationStatusRestricted){
        if (grantedBlock) {
            grantedBlock(AVAuthorizationStatusRestricted);
        }
    }
}
+ (void)lh_requestUserAuthorizationPhotosWith:(void(^)(PHAuthorizationStatus status))completion{
    /** 获取授权状态 */
    PHAuthorizationStatus status=[PHPhotoLibrary authorizationStatus];
    if (status==PHAuthorizationStatusAuthorized) {
        if (completion) {
            completion(status);
        }
    }else{
        if (completion) {
            completion(status);
        }
    }
}
@end
